home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 09 Laramée / Genetic.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-22  |  1.8 KB  |  75 lines

  1.  
  2. #ifndef GENETIC_H
  3. #define GENETIC_H
  4.  
  5. #include "Chromosome.h"
  6. #include "Globals.h"
  7. #include "Simulation.h"
  8.  
  9. /****************************************************************
  10.  * STRUCT Individual
  11.  * A helper for the genetic algorithm, this struct contains an
  12.  * individual strand of DNA and information about its performance 
  13.  * in the field
  14.  ***************************************************************/
  15.  
  16. struct Individual
  17. {
  18.     // Genetic material
  19.     Chromosome DNA;
  20.  
  21.     // Performance score
  22.     double Performance;
  23.  
  24.     // And some stats compiled during simulation; we use them to
  25.     // present a more complete picture of the results
  26.     int StatsKnightsKilled;
  27.     int StatsSheepEaten;
  28.     int StatsDamageTaken;
  29.     int StatsTimeAlive;
  30.     int StatsTimeCaptive;
  31. };
  32.  
  33.  
  34. /****************************************************************
  35.  * CLASS Genetic
  36.  * The genetic algorithm controller itself
  37.  ***************************************************************/
  38.  
  39. class Genetic
  40. {
  41.     // The population we are working on
  42.     Individual Population[ GA_POPULATION_SIZE ];
  43.  
  44.     // The simulation process we are submitting individuals to
  45.     Simulation theSim;
  46.  
  47. public:
  48.     // Construction
  49.     Genetic() {}
  50.  
  51.     // The big mothership method for the whole evolutionary process
  52.     void RunEvolution();
  53.  
  54. private:
  55.     // Making up new individuals from scratch
  56.     void CreateInitialPopulation();
  57.     void MakeRandomIndividual( int which );
  58.  
  59.     // Testing the whole population against the test cases
  60.     void RunGeneration();
  61.  
  62.     // Creating a new generation from the best individuals of
  63.     // the current one
  64.     void BegetNextGeneration();
  65.  
  66.     // Presenting the results to the user
  67.     void ReportGenerationResults( int i );
  68.  
  69.     // The genetic operators
  70.     void Crossover( Chromosome & c1, Chromosome & c2 );
  71.     void Mutation( Chromosome & c );
  72. };
  73.  
  74.  
  75. #endif